import { getCodeList } from '@/api/code'
import { ref } from 'vue'
/**
 * 获取条码列表
 */
export const useGetCodeList = () => {
  // 获取列表加载
  const getCodeListLoading = ref(false)

  // 获取列表请求参数
  const getListParam = ref<CodeAPIRequest.GetCodeList>({
    brandId: '',
    code: '',
    dateOfProductionEndTime: '',
    dateOfProductionStartTime: '',
    endTime: '',
    goods: '',
    goodsModel: '',
    goodsName: '',
    goodsSpec: '',
    limit: 50,
    outboundCode: '',
    page: 1,
    sendGoodsNumber: '',
    startTime: '',
    status: '',
    threeTypeId: '',
    twoTypeId: '',
    type: '',
    typeId: '',
    storestatus: '',
    snCodeStoreOutboundEndDate: '',
    snCodeStoreOutboundStartDate: '',
    codeSource: '',
    registerCode: '',
  })

  // 条码列表
  const codeList = ref<Array<SnCode>>([])

  // 条码列表总条数
  const total = ref(0)

  /**
   * 清空搜索条件
   */
  const clearGetListParam = () => {
    getListParam.value = {
      brandId: '',
      code: '',
      dateOfProductionEndTime: '',
      dateOfProductionStartTime: '',
      endTime: '',
      goods: '',
      goodsModel: '',
      goodsName: '',
      goodsSpec: '',
      limit: 50,
      outboundCode: '',
      page: 1,
      sendGoodsNumber: '',
      startTime: '',
      status: '',
      threeTypeId: '',
      twoTypeId: '',
      type: '',
      typeId: '',
      storestatus: '',
      snCodeStoreOutboundEndDate: '',
      snCodeStoreOutboundStartDate: '',
      codeSource: '',
      registerCode: '',
    }
  }

  /**
   * 获取列表
   */
  const getList = async () => {
    getCodeListLoading.value = true
    const res = await getCodeList(getListParam.value)
    codeList.value = res.data.data.rows
    total.value = Number(res.data.data.total)
    getCodeListLoading.value = false
  }

  return {
    total,
    codeList,
    getListParam,
    getCodeListLoading,
    getList,
    clearGetListParam,
  }
}
